package com.hzhk.happyrent.ui.holder.rent;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.hzhk.happyrent.Constants;
import com.hzhk.happyrent.R;
import com.hzhk.happyrent.bean.rent.BaseBean;
import com.hzhk.happyrent.bean.rent.ProductListModel;
import com.hzhk.happyrent.bean.rent.RentTopModel;
import com.hzhk.happyrent.network.API;
import com.hzhk.happyrent.network.HttpManager;
import com.hzhk.happyrent.network.MyStringResponse;
import com.hzhk.happyrent.ui.activity.rent.ProductDetailsActivity;
import com.hzhk.happyrent.ui.activity.rent.ProductListActivity;
import com.hzhk.happyrent.ui.adapter.rent.HorizontalHomeAdapter;
import com.hzhk.happyrent.ui.view.listview.HorizontalListView;
import com.hzhk.happyrent.ui.view.listview.MaiTianListview;
import com.hzhk.happyrent.utils.ListUtils;
import com.tamic.novate.Throwable;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class HomeCTopViewHolder {

    @BindView(R.id.home_more)
    TextView homeMore;
    @BindView(R.id.comm_top)
    HorizontalListView commTop;
    private View view;


    HorizontalHomeAdapter horizontalHomeAdapter;
    private Context context;
    private List<ProductListModel.DataBean.GoodsBean> goods;

    public HomeCTopViewHolder(View convertView, Context context, ViewGroup viewGroup) {
        this.context = context;
        ButterKnife.bind(this, convertView);
        ((MaiTianListview) viewGroup).setListView(commTop);
        view = convertView;
        initView();
    }

    public void setAction(BaseBean baseBean) {
        ProductListModel productListModel = (ProductListModel) baseBean;
        horizontalHomeAdapter.setList(productListModel.getData().getGoods());
    }

    private void initView() {
        horizontalHomeAdapter = new HorizontalHomeAdapter(context);
        commTop.setAdapter(horizontalHomeAdapter);
        commTop.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(context, ProductDetailsActivity.class);
                intent.putExtra(Constants.GOODS_ID, ((HorizontalHomeAdapter) adapterView.getAdapter()).getItem(i).getId());
                context.startActivity(intent);
            }
        });
    }

    @OnClick({R.id.home_more})
    public void onViewClicked(View view) {
        Intent intent = new Intent(context, ProductListActivity.class);
        context.startActivity(intent);
    }


}